//
//  KSNavigationController.swift
//  Merchant
//
//  Created by liuxm on 2017/8/8.
//  Copyright © 2017年 huanniu. All rights reserved.
//

import UIKit

class KSNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        self.navigationBar.isTranslucent = false
        self.navigationBar.setBackgroundImage(KSTools.createImageWithColor(color: UIColor.white), for: UIBarMetrics.default)
        self.navigationBar.shadowImage = KSTools.createImageWithColor(color: UIColor.clear)
        
        // 替换返还图片
        let backImage = UIImage(named:"Common_Back")?.withRenderingMode(UIImageRenderingMode.alwaysTemplate)
        self.navigationBar.backIndicatorImage = backImage
        self.navigationBar.backIndicatorTransitionMaskImage = backImage
        self.navigationBar.tintColor = KSColor.kColor_3
        
        // 隐藏返还文字
        let barBtn = UIBarButtonItem.appearance()
        barBtn.setTitleTextAttributes([NSAttributedStringKey.foregroundColor:UIColor.white], for: .normal)
        barBtn.setTitleTextAttributes([NSAttributedStringKey.foregroundColor:UIColor.white], for: .highlighted)
        barBtn.setTitleTextAttributes([NSAttributedStringKey.foregroundColor:UIColor.white], for: .selected)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override init(rootViewController: UIViewController) {
        super.init(rootViewController: rootViewController)
        var title:String? = nil
        var image:UIImage? = nil
        var sectImage:UIImage? = nil
        
        if rootViewController.isKind(of: KSHomeViewController.self) {
            title = "工作台"
            image = UIImage(named:"Frame_WorkBench")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
            sectImage = UIImage(named:"Frame_WorkBenchSelect")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        } else if rootViewController.isKind(of: KSSupplyMarketViewController.self) {
            title = "供货市场"
            image = UIImage(named:"Frame_SupplyMarket")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
            sectImage = UIImage(named:"Frame_SupplyMarketSelect")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        }
        
        self.tabBarItem = UITabBarItem(title: title, image: image, selectedImage: sectImage)
        // 修改TabBar字体颜色字体大小
        self.tabBarItem.setTitleTextAttributes([NSAttributedStringKey.foregroundColor:KSColor.kColor_3, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 12)], for: .normal)
        self.tabBarItem.setTitleTextAttributes([NSAttributedStringKey.foregroundColor:KSColor.kColorMainRed, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 12)], for: .selected)
    }
    
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if self.viewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
        }
        
        super.pushViewController(viewController, animated: animated)
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
